import responseHandler from './response-handler'

// 获取要领取的优惠券列表
function getGetCouponInfo(params, success, fail){
    function makeData (originalData) {
        console.log(originalData)
        let _promotions = []
        originalData.promotions && originalData.promotions.forEach(item=>{
            if(item.coupon){
                item.coupon.promotionId = item.id
                _promotions.push(item.coupon)
            }
           
        })
        return {
            promotions: _promotions
        }
      }
      params['methodName'] = 'ListPromotion'
      this.$.get(params)
      .then(responseHandler.success(success, fail, makeData), responseHandler.error(fail))
}

//点击领取优惠券
function receiveConpon(params, success, fail){
    function makeData (originalData) {
      console.log(originalData)
      return {}
    }
    params['methodName'] = 'CreateCouponCode'
    this.$.get(params)
      .then(responseHandler.success(success, fail, makeData), responseHandler.error(fail))
  }
export{
    getGetCouponInfo,
    receiveConpon
}